<template>
  <div class="kpi-preview-wrap">
    <template v-if="dataLabs.length">
      <div class="kpi-preview">
        <actual-logic :dataLabs="dataLabs"></actual-logic>
      </div>
      <div class="kpi-result" :class="{ 'story-result': showStory }" v-if="showStory">
        <div class="story-box">
          <div class="story-title linear-blue">
            <span class="icon"><icon-svg name="iconCalculateResult"></icon-svg></span><br />
            结果预览
          </div>
          <div class="story-content ">
            <div class="result-title">
              <el-row>
                <el-col :span="4" align="center"><span>更新周期</span></el-col>
                <el-col :span="4" align="center" v-if="showStory"><span>运行结果</span></el-col>
                <el-col :span="4" align="center"><span>创建方式</span></el-col>
                <el-col :span="4" align="center" v-if="showStory"><span>上次运行时间</span></el-col>
                <el-col :span="showStory ? 8 : 16">
                  <el-row>
                    <el-col :span="12" align="center">
                      <span>客户标识</span>
                    </el-col>
                    <el-col :span="12" align="center">
                      <span>标签值</span>
                    </el-col>
                  </el-row>
                </el-col>
              </el-row>
            </div>
            <div class="result-content">
              <el-row>
                <el-col :span="4" align="center">
                  <div class="result-info-line">{{ $dict('update_freq')[tagConfigJson.updateFrequency] }}</div>
                </el-col>
                <el-col :span="4" align="center" v-if="showStory">
                  <div class="result-info-line">成功</div>
                </el-col>
                <el-col :span="4" align="center">
                  <div class="result-info-line">标签运算</div>
                </el-col>
                <el-col :span="4" align="center" v-if="showStory">
                  <div class="result-info-line">{{ tagConfigJson.updateTm }}</div>
                </el-col>
                <el-col :span="showStory ? 8 : 16" align="center">
                  <ul class="tag-scrollbar">
                    <li v-for="(item, index) in results" :key="index">
                      <el-row>
                        <el-col :span="12" align="center">
                          {{ item[0] }}
                        </el-col>
                        <el-col :span="12" align="center">
                          {{ item[1] }}
                        </el-col>
                      </el-row>
                    </li>
                  </ul>
                </el-col>
              </el-row>
            </div>
          </div>
        </div>
        <div class="story-box">
          <div class="story-title linear-orange">
            <span class="icon"><icon-svg name="iconCalculateTag"></icon-svg></span><br />
            标签故事
          </div>
          <div class="story-content story-text">
            <el-input type="textarea" v-model="tagStory" :rows="13" resize="none" disabled></el-input>
          </div>
        </div>
      </div>
      <div class="preview-result preview-result-wrap" v-else>
        <h3>结果预览</h3>
        <div class="preview-result-content tag-scrollbar">
          <el-col :span="8" align="center">
            <div class="result-info">
              <img src="~@/assets/img/complete.png" /><br />
              运算成功！
            </div>
          </el-col>
          <el-col :span="16">
            <div class="story-box">
              <div class="story-title linear-blue">
                <span class="icon"><icon-svg name="iconCalculateResult"></icon-svg></span><br />
                结果预览
              </div>
              <div class="story-content tag-scrollbar">
                <div class="result-title">
                  <el-row>
                    <el-col :span="12" align="center">
                      <span>客户标识</span>
                    </el-col>
                    <el-col :span="12" align="center">
                      <span>标签值</span>
                    </el-col>
                  </el-row>
                </div>
                <ul class="result-content">
                  <li v-for="(item, index) in results" :key="index">
                    <el-row>
                      <el-col :span="12" align="center">
                        {{ item[0] }}
                      </el-col>
                      <el-col :span="12" align="center">
                        {{ item[1] }}
                      </el-col>
                    </el-row>
                  </li>
                </ul>
              </div>
            </div>
          </el-col>
        </div>
      </div>
    </template>
    <div class="no-record" v-else>
      <img src="~@/assets/img/no_records.png" /><br />
      暂无内容
    </div>
  </div>
</template>

<script>
import actualLogic from './actual-logic'
export default {
  components: {
    actualLogic
  },
  props: {
    config: {
      type: [Object, String],
      default: () => {}
    },
    dataLabs: {
      type: Array,
      required: true,
      default: () => []
    },
    results: {
      type: Array,
      required: true,
      default: () => []
    },
    showStory: {
      type: Boolean,
      default: false
    },
    tagStory: {
      type: String,
      default: ''
    }
  },
  computed: {
    tagConfigJson() {
      let tagConfigJson = this.config
      if (typeof this.config === 'string') tagConfigJson = JSON.parse(this.config)
      return tagConfigJson
    }
  },
  data() {
    return {
      columns: [
        {
          show: true,
          label: '序号',
          prop: 'order',
          align: 'center'
        },
        {
          show: true,
          label: '标签值',
          prop: 'number',
          align: 'center'
        }
      ]
    }
  },
  methods: {}
}
</script>

<style lang="scss">
.kpi-preview-wrap {
  height: 100%;
  .kpi-preview {
    border: 1px solid #ddd;
    .preview-content {
      margin-top: 16px;
    }
  }
  .preview-result {
    height: calc(100% - 223px);
    margin-top: 20px;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    border: 1px solid #ddd;
    overflow: hidden;
    h3 {
      padding: 20px;
      color: #fff;
      background-color: #475fba;
    }
    .preview-result-content {
      height: calc(100% - 60px);
      overflow-y: auto;
    }
    .result-info {
      display: inline-block;
      font-size: 16px;
      font-weight: bold;
      padding: 15% 20%;
      margin-top: 50px;
      text-align: center;
      color: #666;
      background-color: #f6fbf8;
      img {
        margin-bottom: 20px;
      }
    }
  }
  .story-result {
    border: 0;
    padding: 0 4px;
  }
  .story-box {
    margin-top: 20px;
    height: 310px;
    border-radius: 5px;
    box-shadow: 1px 1px 3px #ddd, -1px -1px 3px #ddd;
    overflow: hidden;
    position: relative;
  }
  .story-title {
    font-size: 17px;
    font-weight: bold;
    width: 200px;
    height: 100%;
    color: #fff;
    text-align: center;
    position: relative;
    &:before {
      width: 100%;
      height: 100%;
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      background: url(~@/assets/img/params_bg.png) no-repeat 0px 0px/100% 100%;
    }
  }
  .icon {
    display: inline-block;
    width: 80px;
    height: 80px;
    background-color: #fff;
    margin: 80px 0 10px;
    border-radius: 50%;
    svg {
      width: 50px;
      height: 50px;
      margin-top: 15px;
    }
  }
  .linear-orange {
    background: linear-gradient(to bottom, #f3bf7c, #f3b172);
    svg {
      color: #f3b172;
    }
  }
  .linear-blue {
    background: linear-gradient(to bottom, #63a3fc, #5188ec);
    svg {
      color: #5188ec;
    }
  }
  .story-content {
    padding-left: 200px;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
  }
  .story-text {
    padding: 13px 15px 13px 215px;
    .el-textarea.is-disabled .el-textarea__inner {
      color: #666;
      cursor: default;
    }
  }
  .result-title {
    height: 60px;
    border-bottom: 1px solid #eee;
    span {
      display: inline-block;
      width: 80%;
      height: 40px;
      line-height: 40px;
      margin: 10px 0 10px 0;
      background-color: #fcf5e5;
      border-radius: 20px;
    }
  }
  .result-content {
    height: calc(100% - 60px);
    overflow-y: auto;
    li {
      height: 40px;
      line-height: 40px;
    }
  }
  .preview-result-wrap {
    .story-box {
      margin-right: 20px;
    }
  }
  .no-record {
    margin: 20px 0;
    text-align: center;
    img {
      margin-bottom: 10px;
    }
  }
}
</style>
